<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>demo主信息列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/systemStatic/style/admin.css">
    <link rel="stylesheet" href="/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="/css/public.css">
    <script type="text/javascript">
        var __ctx = "";
    </script>
</head>
<body>

<div style="margin: 10px">
    <table id="wDemozbTable" lay-filter="wDemozbTable"></table>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="wDemozbHeaderToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                <span>新增</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="clears">
                <i class="layui-icon layui-icon-refresh"></i>
                <span>重置</span>
            </a>
        </div>
        <form class="layui-form" action="" lay-filter="wDemozbQueryForm" style="margin-right: 30px;">
            <div class="layui-row" style="margin-top: 10px;">
                <div class="selch table-top-filter">
                        <div class="table-filter-alone">
                                <label class="layui-form-label">文字</label>
                                <input type="text" class="layui-input filter-value" name="Q_wz_SL" placeholder="文字"/>
                        </div>
                        <div class="table-filter-alone">
                                <label class="layui-form-label">开始时间</label>
                                <input type="text" class="layui-input start_time1 filter-value" name="Q_beginKssj_DL" placeholder="开始时间"/>
                                <span style="float:left;margin-left:38px;">—</span>
                                <input type="text" class="layui-input end_time1 filter-value" name="Q_endKssj_DG" placeholder="结束时间" style="margin-left:38px;"/>
                        </div>
                        <div class="table-filter-alone">
                                <label class="layui-form-label">结束时间</label>
                                <input type="text" class="layui-input start_time2 filter-value" name="Q_beginJssj_DL" placeholder="开始时间"/>
                                <span style="float:left;margin-left:38px;">—</span>
                                <input type="text" class="layui-input end_time2 filter-value" name="Q_endJssj_DG" placeholder="结束时间" style="margin-left:38px;"/>
                        </div>
                </div>
            </div>
        </form>
    </div>

</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="wDemozbRightToolsBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="particulars">详情</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="/public/component.js" type="text/javascript"></script>
<script src="/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'setter', 'form', 'common','totalFilter','commons','jquery','layer'], function () {
        var table = layui.table;
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var commons = layui.commons;
        var $ = layui.jquery;
        var layer = layui.layer;
        var totalFilter = layui.totalFilter;
        common.tableSort('wDemozbTable');
        var tableH=commons.tabHeight();

        //第一个实例
        table.render({
            elem: '#wDemozbTable'
            ,height:tableH
            ,url: serverPath.basePath + '/demo/wDemozb/list'
            ,page: true //开启分页
            ,toolbar: '#wDemozbHeaderToolsBar'
            ,method: 'post'
            ,autoSort: false //是否排序
            ,cols: [[ //表头
                {field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
                ,{type: 'checkbox', fixed: 'left'}
                ,{field: 'wz', title: '文字',sort:true, sortname: 'wz'}
                //如需转换为:yyyy-MM-dd HH:mm:ss: return commons.timeData(d.kssj,"1");
                //如需转换为HH:mm:ss: return commons.timeData(d.kssj,"2");
                // 当前转换后的格式为yyyy-MM-dd: return commons.timeData(d.kssj);
                ,{field: 'kssj', title: '开始时间',sort:true, sortname: 'kssj',templet: function (d) {
                    return commons.timeData(d.kssj);
                }}
                //如需转换为:yyyy-MM-dd HH:mm:ss: return commons.timeData(d.jssj,"1");
                //如需转换为HH:mm:ss: return commons.timeData(d.jssj,"2");
                // 当前转换后的格式为yyyy-MM-dd: return commons.timeData(d.jssj);
                ,{field: 'jssj', title: '结束时间',sort:true, sortname: 'jssj',templet: function (d) {
                    return commons.timeData(d.jssj);
                }}
                ,{field: 'fjsz', title: '附件上传',sort:true, sortname: 'fjsz',templet:function (data) {
//                    数据列表附件回显没有附件时显示无，有附件时显示名字
                    if (data.fjsz&&data.fjsz!=""){
                        return JSON.parse(data.fjsz)[0].name
                    }else {
                        return '无'
                    }

                }}
                ,{field: 'tpsz', title: '图片上传',sort:true, sortname: 'tpsz',templet:function (data) {
//                    数据列表图片回显没有图片时显示无，有图片时根据路径加载图片
                    if (data.tpsz&&data.tpsz!=""){
                        return '<img src="' + serverPath.formPath + setter.sysLinkPath + 'attachFile/getFileById?fileId=' + JSON.parse(data.tpsz)[0] + '" />'
                    }else {
                        return '无'
                    }

                }}
                ,{
                    fixed: 'right',
                    align: 'center',
                    title: '管理',
                    toolbar: '#wDemozbRightToolsBar'
                }
            ]],done:function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
        });

        totalFilter.init('wDemozbTable');
        dateReflash()
        function dateReflash() {
            commons.reflashDate({startName:'.start_time1',endName:'.end_time1'});
            commons.reflashDate({startName:'.start_time2',endName:'.end_time2'});
            commons.reflashDate({startName:'.start_time3',endName:'.end_time3'});
            commons.reflashDate({startName:'.start_time4',endName:'.end_time4'});
        }

        function reflashQuery(isClear) {
            common.tableConditionRender("wDemozbTable","wDemozbQueryForm",{where:{}},isClear);
        }

        table.on('toolbar(wDemozbTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2,
                        title: ['新增数据'],
                        area: ['100%', '100%'],
                        content: serverPath.basePath + "/demo/wDemozb/view/add",
                        end:function () {
                            reflashQuery(true);
                            dateReflash();
                        }
                    });
                    break;
                case "query":
                    reflashQuery(false);
                    dateReflash();
                    break;
                case "clears":
                    reflashQuery(true);
                    dateReflash();
                    break;

            };
        });

        table.on('tool(wDemozbTable)', function(obj) {
            var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
            switch(layEvent){
                case "edit":
                    layer.open({
                        type: 2,
                        area: ['100%', '100%'],
                        title: ['修改数据'],
                        content: serverPath.basePath + '/demo/wDemozb/view/add?id='+data.id,
                        end:function () {
                            reflashQuery(true);
                            dateReflash();
                        }
                    });
                    break;
                case "particulars":
                    layer.open({
                        type: 2,
                        area: ['100%', '100%'],
                        title: ['修改数据'],
                        content: serverPath.basePath + '/demo/wDemozb/view/particulars?id='+data.id
                    });
                    break;
                case "del":
                    delFun(data,data.id);
                    break;
            }
        });

        function delFun(data,id) {
            if (data.length === 0) {
                layer.msg('请先选择一行数据!');
            } else {
                layer.confirm('确定删除当前数据吗?', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.basePath + "/demo/wDemozb/del",
                        type: "post",
                        data: {id:id},
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                            dateReflash();
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                            dateReflash();
                        }
                    })
                })
            }
        }

        window.Initialization = function () {
            dateReflash();
        };
        /*刷新时间控件*/
        dateReflash();
        common.tableSort("wDemozbTable",{show:window.Initialization});
    });
</script>
</body>
</html>